package com.xposed.aliproxy.thread;

import android.content.Context;

import com.xposed.aliproxy.db.AliTradeModel;
import com.xposed.aliproxy.db.DBUtil;
import com.xposed.aliproxy.utils.ParamConfig;

import java.util.Iterator;
import de.robv.android.xposed.XposedBridge;

public class BatchUploadAliTradeThread extends Thread {
    public boolean isAppDestroy = false;  // 程序是否已经关闭
    private Context context;
    private DBUtil dbUtil;

    public BatchUploadAliTradeThread(Context context, DBUtil dBUtil) {
        this.context = context;
        this.dbUtil = dBUtil;
    }

    @Override
    public void run() {
        super.run();
        ParamConfig paramConfig = ParamConfig.getInstance(this.context);
        String agentId = paramConfig.getString("agentId", "");
        String aliAccount = paramConfig.getString("aliAccount", "");
        while (true) {
            try {
                Thread.sleep(10000);
                if (!this.isAppDestroy) {
                    Iterator it = this.dbUtil.queryAlitradeByParams(agentId, aliAccount).iterator();
                    while (it.hasNext()) {
                        new UploadAliTradeThread(this.context, (AliTradeModel) it.next()).start();
                    }
                    Thread.sleep(60000);
                } else {
                    return;
                }
            } catch (Throwable th) {
                XposedBridge.log(th);
            }
        }
    }
}
